<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        body {
            background-color: #f7f7f7;
        }
        .bg {
            width: 1400px;
            height: 200px;
            float: left;
            position: relative;
            flex-wrap: wrap;
            margin: 200px auto;
        }

        img {
            width: 300px;
            height: 200px;
        }

        .img {
            width: 100%;
            height: 170px;
            display: flex;
            transition: 0.3s;
        }
        .box {
            width: 300px;
            height: 200px;
            box-shadow: 0px 0px 20px;
            border: 1px solid black;
            margin-left: 20%;
            float: left;
            overflow: hidden;
            padding: 0;
        }

        .description {
            position: absolute;
        }

        .big {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: rgba(0, 0, 0, 20%);
            display: inline-block;
            position: relative;
        }
    </style>
</head>

<body>
    <div class="bg">
        <div class="box">
            <div class="img">
                <img src="./img1.jpg">
                <img src="./img2.jpg">
                <img src="./img3.jpg">
                <img src="./img4.jpg">
                <img src="./img5.jpg">
            </div>
            <div class="description">
                <div class="big"></div>
                <div class="big"></div>
                <div class="big"></div>
                <div class="big"></div>
                <div class="big"></div>
            </div>

        </div>
    </div>
    </div>
    </div>
    <script>

        let box = document.querySelector('.box');
        let big = document.querySelectorAll('.big');
        let imgs = document.querySelectorAll('img');
        let img = document.querySelector('.img');
        fn()
        console.log(imgs[0])
        for (let i = 0; i < big.length; i++) {
                    big[0].style.background = "#fff";
                    big[i].addEventListener('click', function () {
                        for (let i = 0; i < imgs.length; i++) {
                            for (let i = 0; i < big.length; i++) {
                                big[i].style.background = "rgba(0, 0, 0, 20%)";
                                imgs[i].style.backgroundImage = imgs[i];
                                console.log(imgs[i]);
                            }
                            this.style.background = "#fff";
                        }
                    })
                }

                let child = img.lastChild
        console.log(box.scrollWidth);
        let num = img.offsetHeight + 850;
        function fn() {
            scrolls = setInterval(() => {
                if (box.scrollLeft >= num) {
                    box.scrollLeft = 0;
                    clearInterval();
                    console.log(box.scrollLeft)
                } else {
                    box.scrollLeft += 1;
                    clearInterval
                    // console.log(box.scrollLeft)
                }
                
            })
        }

    </script>
</body>

</html>